package com.hzhc.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzhc.entity.SmsChannel;
import com.hzhc.mapper.SmsChannelMapper;
import com.hzhc.service.SmsChannelService;
import com.hzhc.utils.ResultUtil;
import com.hzhc.vo.SmsChannelVo;
import lombok.RequiredArgsConstructor;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author dongcy
 * @date 2024/6/17 10:59
 * @description SmsChannelServiceImpl
 */
@Service
@RequiredArgsConstructor
public class SmsChannelServiceImpl extends ServiceImpl<SmsChannelMapper, SmsChannel> implements SmsChannelService {

    @Override
    public List<SmsChannelVo> getMessageTypeList(Page<SmsChannelVo> page, SmsChannelVo vo) {
        IPage<SmsChannelVo> iPage = baseMapper.getMessageTypeList(page,vo);
        return iPage.getRecords();
    }

    @Override
    public ResultUtil<T> addMessageType(SmsChannelVo vo) {
        SmsChannel channel = new SmsChannel();
        BeanUtils.copyProperties(vo,channel);
        channel.setCreateTime(LocalDateTime.now());
        boolean b = save(channel);
        if (b){
            return ResultUtil.ok();
        }
        return ResultUtil.fail();
    }

    @Override
    public ResultUtil<T> delMessageType(Long id) {
        SmsChannel channel = getById(id);
        channel.setDisable(1);
        boolean b = updateById(channel);
        if (b){
            return ResultUtil.ok();
        }
        return ResultUtil.fail();
    }

    @Override
    public ResultUtil<T> updateMessageType(SmsChannelVo vo) {
        SmsChannel channel = getById(vo.getId());
        channel.setApiAccount(vo.getApiAccount());
        channel.setApiSecretKey(vo.getApiSecretKey());
        channel.setRemark(vo.getRemark());
        channel.setSendCallbackUrl(vo.getSendCallbackUrl());
        channel.setSdkAppId(vo.getSdkAppId());
        channel.setRegion(vo.getRegion());
        channel.setSenderId(vo.getSenderId());
        channel.setExtendCode(vo.getExtendCode());
        channel.setService(vo.getService());
        channel.setSignature(vo.getSignature());
        channel.setEnableStatus(vo.getEnableStatus());
        channel.setUpdateUserId(vo.getUpdateUserId());
        channel.setUpdateTime(LocalDateTime.now());
        boolean b = updateById(channel);
        if (b){
            return ResultUtil.ok();
        }
        return ResultUtil.fail();
    }

    @Override
    public List<SmsChannel> getMsgChannel(SmsChannel channel) {
        return baseMapper.getMsgChannel(channel);
    }


}
